[HEADER]
	VERSION		00.00.00.00
	DESCRIPTION Wood Example
	COPYRIGHT	Imagination Technologies Ltd.
[/HEADER]

[TEXTURES]
[/TEXTURES]

[VERTEXSHADER]
	NAME myVertShader
	[GLSL_CODE]
		attribute highp vec4	myVertex;
		attribute mediump vec3	myNormal;
		attribute mediump vec4	myUV;
		uniform mediump mat4	myMVPMatrix;
		uniform mediump mat3	myModelViewIT;
		uniform mediump mat4	myModelView;

		const mediump vec3		LightPosition = vec3(0.0, 0.0, 4.0);
		const mediump float		Scale = 0.25;

		varying mediump float lightIntensity;
		varying mediump vec3 Position;

		void main(void)
		{
			mediump vec4 pos = myModelView * myVertex;
			Position = vec3(myVertex) * Scale;
			mediump vec3 tnorm = myModelViewIT * myNormal;
			lightIntensity = abs(dot(normalize(LightPosition - vec3(pos)), tnorm)) * 1.5;
			gl_Position = myMVPMatrix * myVertex;
		}
	[/GLSL_CODE]
[/VERTEXSHADER]

[FRAGMENTSHADER]
	NAME myFragShader
	[GLSL_CODE]
		const mediump float GrainSizeRecip = 7.0;
		const mediump vec3  DarkColor = vec3(0.6, 0.3, 0.1);
		const  mediump vec3 spread = vec3(0.15, 0.075, 0.0);

		varying mediump float lightIntensity; 
		varying highp vec3 Position;

		void main (void)
		{
			//
			// cheap noise
			//
			mediump vec3 location = Position;
			mediump vec3 floorvec = vec3(floor(10.0 * Position.x), 0.0, floor(10.0 * Position.z));
			mediump vec3 noise = Position * 10.0 - floorvec - 0.5;
			noise *= noise;
			location += noise * 0.12;
		
			//
			// distance from axis
			//
			mediump float dist = location.x * location.x + location.z * location.z;
			mediump float grain = dist * GrainSizeRecip;

			//
			// grain effects as function of distance
			//
			mediump float brightness = fract(grain);    
			if (brightness > 0.5) 
				brightness = 1.0 - brightness;
			mediump vec3 color = DarkColor + brightness * spread;

			//
			// apply lighting effects from vertex processor
			//
			color = clamp(color * lightIntensity, 0.0, 1.0); 

			gl_FragColor = vec4(color, 1.0);
		}
	[/GLSL_CODE]
[/FRAGMENTSHADER]

[EFFECT]
	NAME myEffect

	ATTRIBUTE	myVertex			POSITION
	ATTRIBUTE	myNormal			NORMAL
	UNIFORM		myMVPMatrix			WORLDVIEWPROJECTION
	UNIFORM		myModelViewIT		WORLDVIEWIT

	VERTEXSHADER myVertShader
	FRAGMENTSHADER myFragShader
[/EFFECT]
